﻿using FluentNHibernate.Mapping;
using cludg.Domain.Content.Stories;
using cludg.Domain.Users;

namespace cludg.Repository.NHibernate.Config.Content
{
	public class OfferMap : ClassMap<Offer>
	{
		public OfferMap()
		{
			Table("Offers");
			Cache.ReadWrite();
			Id(x => x.Id).Length(50)
				.GeneratedBy.Custom<Utils.IdentifierGenerator>()
				.Default("");

			References<User>(x => x.Author)
				.Column("AuthorId")
				.LazyLoad();
			Map(x => x.AnonymouseAuthorName).Length(50);
			Map(x => x.CreationTime);

			Map(x => x.Comment).Length(500);
			Map(x => x.Title).Length(200);
			References(x => x.Subject)
				.Column("SubjectId")
				.Cascade.SaveUpdate()
				.Not.LazyLoad();

			Map(x => x.State);
			Map(x => x.OfferingTime);
			References(x => x.OfferedBy)
				.Column("OfferedByUserId")
				.Not.LazyLoad();
			Map(x => x.ApprovedStoryId)
				.Length(50);
		}
	}
}